package design.simdi.code.final_paper.utils;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.form.AjaxFallbackButton;
import org.apache.wicket.extensions.wizard.IWizard;
import org.apache.wicket.extensions.wizard.IWizardModel;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.model.ResourceModel;

/**
 * 
 * @author Marius Dumitriu - (Jun 21, 2010 - 7:04:02 PM)
 * 
 */
public abstract class WizardAjaxButton extends AjaxFallbackButton {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private final IWizard wizard;

	@SuppressWarnings("unchecked")
	public WizardAjaxButton(String id, IWizard wizard, final Form form, String labelResourceKey) {

		super(id, form);
		this.setLabel(new ResourceModel(labelResourceKey));
		this.wizard = wizard;
	}

	public WizardAjaxButton(String id, IWizard wizard, String labelResourceKey) {
		this(id, wizard, null, labelResourceKey);
	}

	public IWizard getWizard() {
		return wizard;
	}

	protected final IWizardModel getWizardModel() {
		return getWizard().getWizardModel();
	}

	@SuppressWarnings("unchecked")
	protected final void onSubmit(AjaxRequestTarget target, Form form) {
		onClick(target, form);
	}

	@SuppressWarnings("unchecked")
	protected abstract void onClick(AjaxRequestTarget target, Form form);

}
